package com.zxy.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2配置类
 * @author ZENG.XIAO.YAN
 * @version 1.0
 */
@Configuration
@EnableSwagger2
@Profile(value = { "home", "dev" }) // 只有dev和home环境下会生成swagger
public class Swagger2Config {
	
	// 预览地址:swagger-ui.html
	@Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zxy.demo.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("SpringBoot + Quartz 实现动态定时任务")
                .description("项目源码参考：https://gitee.com/jordancode/dynamicQuartz")
                .termsOfServiceUrl("http://www.cnblogs.com/zeng1994/")
                .contact(new Contact("zeng1994", "http://www.cnblogs.com/zeng1994/", null))
                .version("1.0")
                .build();
    }
}
